package com.ruoyi.inventory.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.inventory.domain.MaterialInventory;
import com.ruoyi.inventory.service.IMaterialInventoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物资库存Controller
 * 
 * @author ruoyi
 * @date 2025-05-07
 */
@RestController
@RequestMapping("/inventory/inventory")
public class MaterialInventoryController extends BaseController
{
    @Autowired
    private IMaterialInventoryService materialInventoryService;

    /**
     * 查询物资库存列表
     */
    @PreAuthorize("@ss.hasPermi('inventory:inventory:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaterialInventory materialInventory)
    {
        startPage();
        List<MaterialInventory> list = materialInventoryService.selectMaterialInventoryList(materialInventory);
        return getDataTable(list);
    }

    /**
     * 导出物资库存列表
     */
    @PreAuthorize("@ss.hasPermi('inventory:inventory:export')")
    @Log(title = "物资库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialInventory materialInventory)
    {
        List<MaterialInventory> list = materialInventoryService.selectMaterialInventoryList(materialInventory);
        ExcelUtil<MaterialInventory> util = new ExcelUtil<MaterialInventory>(MaterialInventory.class);
        util.exportExcel(response, list, "物资库存数据");
    }

    /**
     * 获取物资库存详细信息
     */
    @PreAuthorize("@ss.hasPermi('inventory:inventory:query')")
    @GetMapping(value = "/{inventoryId}")
    public AjaxResult getInfo(@PathVariable("inventoryId") Long inventoryId)
    {
        return success(materialInventoryService.selectMaterialInventoryByInventoryId(inventoryId));
    }

    /**
     * 新增物资库存
     */
    @PreAuthorize("@ss.hasPermi('inventory:inventory:add')")
    @Log(title = "物资库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialInventory materialInventory)
    {
        return toAjax(materialInventoryService.insertMaterialInventory(materialInventory));
    }

    /**
     * 修改物资库存
     */
    @PreAuthorize("@ss.hasPermi('inventory:inventory:edit')")
    @Log(title = "物资库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialInventory materialInventory)
    {
        return toAjax(materialInventoryService.updateMaterialInventory(materialInventory));
    }

    /**
     * 删除物资库存
     */
    @PreAuthorize("@ss.hasPermi('inventory:inventory:remove')")
    @Log(title = "物资库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inventoryIds}")
    public AjaxResult remove(@PathVariable Long[] inventoryIds)
    {
        return toAjax(materialInventoryService.deleteMaterialInventoryByInventoryIds(inventoryIds));
    }
}
